package ch02.classPath.Entry;

import java.io.File;
import java.io.IOException;

/**
 * 该类用于处理 classPath 为 aa/bb/* 的时候
 *
 */
public class WildcardEntry extends Entry{
    public CompositeEntry compositeEntry;

    public WildcardEntry(String jrelibPath) {
        String baseDir = jrelibPath.substring(0, jrelibPath.length() -1);

        File dir = new File(baseDir);
        File[] files = dir.listFiles();

        compositeEntry = new CompositeEntry();
        for (int i = 0; i<files.length; i++){
            if(files[i].isFile() && files[i].getName().contains(".jar")){
                compositeEntry.addEntry(new ZipJarEntry(baseDir, files[i].getName()));
            }
        }
    }

    @Override
    public byte[] readClass(String className) throws IOException {
        return compositeEntry.readClass(className);
    }

    @Override
    public String string() {
        return null;
    }
}
